package com.sky.controller.admin;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderDetailVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.PathVariable;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersRejectionDTO;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;


@RestController("adminOrderController")
@Slf4j
@RequestMapping("/admin/order")
@Api(tags = "商家订单管理")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 查看订单
     * @param id
     * @return
     */
    @ApiOperation("查看订单")
    @GetMapping("/details/{id}")
    public Result orderDetail(@PathVariable Long id){
        log.info("查看订单id：{}", id);
        OrderDetailVO orderDetailVO = orderService.selectOrder(id);
        return Result.success(orderDetailVO);
    }
/**
     * 订单搜索
     * @param dto
     * @return
     */
    @GetMapping("/conditionSearch")
    @ApiOperation("订单搜索")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO dto) {
        log.info("订单搜索：{}", dto);
        PageResult pageResult = orderService.conditionSearch(dto);
        return Result.success(pageResult);

    }

        @PutMapping("/confirm")
        @ApiOperation("接单")
        public Result confirm (@RequestBody OrdersConfirmDTO ordersConfirmDTO){
            orderService.confirm(ordersConfirmDTO);
            return Result.success();
        }

        @PutMapping("/rejection")
        @ApiOperation("拒单")
        public Result rejection (@RequestBody OrdersRejectionDTO ordersRejectionDTO) throws Exception {
            orderService.reject(ordersRejectionDTO);
            return Result.success();
        }
    }
